<?php
##############################################
#
#   地区分类
# @ Time : 2017-1-26 - 下午6:24:16
# @ Author : JiangYongWei <1085562810@qq.com>
# @ Encoding : UTF-8 language : PHP
#
##############################################



namespace Home\Model;

class LocalityModel extends IndexBaseModel{
	/*地区表  */
	protected $tableName = 'locality';
	
	/**
	 * 按等级获取地区数据
	 */
	public function getLocalityLevel($pid){
		return $this->field('lname,lid')->where(array('pid'=>$pid,'is_display'=>1))->order('sort asc')->select();
	}
	
	public function getLocalityPid($lid){
 		$result = $this -> field('pid') -> where(array('lid'=>$lid)) -> find();
 		return $result['pid'];
	}
	
	/**
	 * 获取所有的子地区id
	 */
	public function getSonLocality($lid){
		$result = $this -> field('lid') -> where(array('pid'=>$lid)) -> select();
		if(is_null($result)){
			$result = array(array('lid' => $lid));
		}
		return $result;
	}
	
}